(function (G) {
    G.vue({
      data: {
        location:[],
        models: {},
        values:{},
        userId:'',
        levels:{},
        longitude:0,
        latitude:0,
        address:''
      },
      methods: {
        save(){
            var data = this.selectComponent('#form').submit()
            if(!data) return false
            let userInfo = G.Storage.get('userInfo')
            data.userId = userInfo.userId
            data.userName = userInfo.userName
            data.toUsers = typeof data.toUsers == 'string' ? JSON.parse(data.toUsers) : []
            let toUsers = [],userNames = []
            for(let i = 0; i < data.toUsers.length; i ++){
                toUsers.push(data.toUsers[i].value)
                userNames.push(data.toUsers[i].name)
            }
            data.toUsers = userNames.join(',')
            toUsers = toUsers.join(',')
            G.post('/v1/task/add',{
                userId:userInfo.userId,
                flowId:'1641733895592480768',
                data,
                toUsers,
                // title:`[${this.data.types[data.type]}]${data.msg}(${this.data.levels[data.level]})`
                title:`[${data.safeTypeName}]${data.msg}(${this.data.levels[data.level]})`
            }).then(res => {
                if(!res.errorMsg){
                    data.f_taskId = res.task.id
                    data.userId = userInfo.userId
                    data.safeTypeId = '1651229281306677248'
                    G.post('/api/model/safeCase',data).then(res => {
                        G.toask('问题上报成功').then(() => {
                            this.$back()
                        })
                    })
                }
                G.addClock({
                    longitude:this.data.longitude,
                    latitude:this.data.latitude,
                    address:this.data.address,
                    msg:'安全巡查'
                })
            })
        }
      },
      mounted(options) {
        G.get('/api/model/f_node',{id:'n1680254862614'}).then(node => {
            let form = JSON.parse(node.form),levels = {}
            // for(let i = 0; i < form.type.attr.actions.length; i ++) types[form.type.attr.actions[i].value] = form.type.attr.actions[i].name
            // for(let i = 0; i < form.level.attr.actions.length; i ++) levels[form.level.attr.actions[i].value] = form.level.attr.actions[i].name
            this.setData({
                // types,
                levels,
                userId:G.Storage.get('userInfo').userId,
                longitude:options.longitude,
                latitude:options.latitude,
                address:options.address
            })
            form.toUsers = {
                label: '责任人',
                rule: {
                    NotNull: true
                },
                attr: {
                    type: 'userselect',
                    max:2
                },
                unList: true,
                type: 'customer'
            }
            this.selectComponent('#form').init(form, options, false,[]);
        })    
      }
    })
  })(wx.$)